home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 5748 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.6 KB  |  51 lines

  1. Path: rcp6.elan.af.mil!rscernix!danpop
  2. From: danpop@mail.cern.ch (Dan Pop)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: writing to .exe file
  5. Date: 20 Feb 96 18:43:57 GMT
  6. Organization: CERN European Lab for Particle Physics
  7. Message-ID: <danpop.824841837@rscernix>
  8. References: <4g961o$gdr@ultra.sonic.net> <4gcg2n$6fd@kannews.ca.newbridge.com>  <Pine.SOL.3.90.960220111544.24981F-100000@eddie>
  9. NNTP-Posting-Host: ues5.cern.ch
  10. X-Newsreader: NN version 6.5.0 #7 (NOV)
  11.  
  12. In <Pine.SOL.3.90.960220111544.24981F-100000@eddie> Darrell Grainger <a378grai@cdf.toronto.edu> writes:
  13.  
  14. >On 20 Feb 1996, Glen Miner wrote:
  15. >
  16. >> >I would like  to save data ( a string ) from one run of a (dos) program 
  17. >> >to the next by writing it to the .exe file. does this sound doable?
  18. >> 
  19. >> Yes. It's totally fine. Just append junk to the end of the exe file. 
  20. >
  21. >It should be noted that this might not work on some operating systems. I
  22. >have seen systems that break the program into various parts based on
  23. >information in the program file. If there is extra data at the end of the
  24. >program the operating system will consider the program corrupt and fail to
  25. >load.
  26.  
  27. And on some platforms you simply cannot open an executable file which
  28. is running in write or update mode:
  29.  
  30.     cnwgs1:/tmp 74> cat test.c
  31.     #include <stdio.h>
  32.  
  33.     main(int argc, char **argv)
  34.     {
  35.     if (fopen(argv[0], "r+") == NULL) perror(argv[0]);
  36.     else puts("It worked!");
  37.     return 0;
  38.     }
  39.     cnwgs1:/tmp 75> cc test.c
  40.     cnwgs1:/tmp 76> ./a.out
  41.     ./a.out: Text file busy
  42.  
  43. Of course, DOS isn't one of those platforms.
  44.  
  45. Dan
  46. --
  47. Dan Pop
  48. CERN, CN Division
  49. Email: danpop@mail.cern.ch 
  50. Mail:  CERN - PPE, Bat. 31 R-004, CH-1211 Geneve 23, Switzerland
  51.